package com.core.zyyz.amc.modules.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.hutool.core.bean.BeanUtil;
import com.core.common.utils.StringUtils;
import com.core.common.utils.uuid.UUID;
import com.core.zyyz.amc.modules.service.AmcBusinessCategoriesService;
import kotlin.jvm.internal.PackageReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.core.zyyz.amc.modules.mapper.AmcProjectSubnodeMapper;
import com.core.zyyz.amc.modules.domain.AmcProjectSubnode;
import com.core.zyyz.amc.modules.service.AmcProjectSubnodeService;

/**
 * 子节点配置Service业务层处理
 *
 * @author LiuFushun
 * @date 2024-11-20
 */
@Service
public class AmcProjectSubnodeServiceImpl implements AmcProjectSubnodeService
{
    @Autowired
    private AmcProjectSubnodeMapper amcProjectSubnodeMapper;
    @Autowired
    private AmcBusinessCategoriesService amcBusinessCategoriesService;
    /**
     * 查询子节点配置
     *
     * @param subnodeId 子节点配置主键
     * @return 子节点配置
     */
    @Override
    public Map<String, Object> selectAmcProjectSubnodeBySubnodeId(String subnodeId) {
        AmcProjectSubnode amcProjectSubnode = amcProjectSubnodeMapper.selectAmcProjectSubnodeBySubnodeId(subnodeId);
        Map<String, Object> map = BeanUtil.beanToMap(amcProjectSubnode);
        List<HashMap<String ,Object>> mapList = amcBusinessCategoriesService.getCategoriesMapBySubnodeId(subnodeId);
        String baseProjectType = "";
        String projectTypeName ="";
        if(mapList.size()>0){
            for(HashMap<String ,Object> bizmap : mapList){
                baseProjectType += bizmap.get("bizId")+",";
                projectTypeName += bizmap.get("bizName")+",";
            }
            map.put("baseProjectType",StringUtils.isNotEmpty(baseProjectType)?baseProjectType.substring(0,baseProjectType.length()-1).split(","):baseProjectType);
            map.put("projectTypeName",StringUtils.isNotEmpty(projectTypeName)?projectTypeName.substring(0,projectTypeName.length()-1).split(","):projectTypeName);
        }
        return map;
    }

    /**
     * 查询子节点配置列表
     *
     * @param nodeCode 子节点配置Code
     * @return 子节点配置
     */
    @Override
    public List<AmcProjectSubnode> querySubNodeByNode(String nodeCode)
    {
        return amcProjectSubnodeMapper.querySubNodeByNode(nodeCode);
    }

    /**
     * 查询子节点配置列表
     *
     * @param amcProjectSubnode 子节点配置
     * @return 子节点配置
     */
    @Override
    public List<AmcProjectSubnode> selectAmcProjectSubnodeList(AmcProjectSubnode amcProjectSubnode)
    {
        return amcProjectSubnodeMapper.selectAmcProjectSubnodeList(amcProjectSubnode);
    }

    /**
     * 新增子节点配置
     *
     * @param amcProjectSubnode 子节点配置
     * @return 结果
     */
    @Override
    public int insertAmcProjectSubnode(AmcProjectSubnode amcProjectSubnode) {
        return amcProjectSubnodeMapper.insertAmcProjectSubnode(amcProjectSubnode);
    }

    /**
     * 修改子节点配置
     *
     * @param amcProjectSubnode 子节点配置
     * @return 结果
     */
    @Override
    public int updateAmcProjectSubnode(AmcProjectSubnode amcProjectSubnode)
    {
        return amcProjectSubnodeMapper.updateAmcProjectSubnode(amcProjectSubnode);
    }

    /**
     * 批量删除子节点配置
     *
     * @param subnodeIds 需要删除的子节点配置主键
     * @return 结果
     */
    @Override
    public int deleteAmcProjectSubnodeBySubnodeIds(String[] subnodeIds)
    {
        return amcProjectSubnodeMapper.deleteAmcProjectSubnodeBySubnodeIds(subnodeIds);
    }

    /**
     * 删除子节点配置信息
     *
     * @param subnodeId 子节点配置主键
     * @return 结果
     */
    @Override
    public int deleteAmcProjectSubnodeBySubnodeId(String subnodeId)
    {
        return amcProjectSubnodeMapper.deleteAmcProjectSubnodeBySubnodeId(subnodeId);
    }
}
